﻿namespace MDXStudio.MdSchema
{
    using System;
    using System.Data;

    internal class MdHierarchy : IMdObject
    {
        private string mAllMember;
        private string mCubeName;
        private string mDefaultMember;
        private string mDescription;
        private eDimensionType mDimensionType;
        private string mDimensionUniqueName;
        private string mDisplayFolder;
        private int mGroupingBehaviour;
        private string mHierarchyCaption;
        private int mHierarchyCardinality;
        private string mHierarchyName;
        private int mHierarchyOrdinal;
        private eHierarchyOrigin mHierarchyOrigin;
        private string mHierarchyUniqueName;
        private eInstanceSelection mInstanceSelection;
        private bool mIsVisible;
        private bool mIsWriteEnabled;
        private MdObjectList<MdLevel> mLevelList;
        private eHierarchyStructure mStructure;
        private string mUniqueCaption;

        public MdHierarchy(DataRow pRow)
        {
            this.mCubeName = (string) pRow["CUBE_NAME"];
            this.mDimensionUniqueName = (string) pRow["DIMENSION_UNIQUE_NAME"];
            this.mHierarchyUniqueName = (string) pRow["HIERARCHY_UNIQUE_NAME"];
            this.mHierarchyName = (pRow["HIERARCHY_NAME"] is DBNull) ? string.Empty : ((string) pRow["HIERARCHY_NAME"]);
            this.mHierarchyCaption = (string) pRow["HIERARCHY_CAPTION"];
            this.mDescription = (pRow["DESCRIPTION"] is DBNull) ? string.Empty : ((string) pRow["DESCRIPTION"]);
            this.mAllMember = (pRow["ALL_MEMBER"] is DBNull) ? string.Empty : ((string) pRow["ALL_MEMBER"]);
            this.mDefaultMember = (string) pRow["DEFAULT_MEMBER"];
            this.mDisplayFolder = ((pRow.Table.Columns.IndexOf("HIERARCHY_DISPLAY_FOLDER") < 0) || (pRow["HIERARCHY_DISPLAY_FOLDER"] is DBNull)) ? string.Empty : ((string) pRow["HIERARCHY_DISPLAY_FOLDER"]);
            this.mHierarchyOrdinal = (int) ((uint) pRow["HIERARCHY_ORDINAL"]);
            this.mHierarchyCardinality = (int) ((uint) pRow["HIERARCHY_CARDINALITY"]);
            this.mIsWriteEnabled = (bool) pRow["IS_READWRITE"];
            this.mIsVisible = (pRow.Table.Columns.IndexOf("HIERARCHY_IS_VISIBLE") < 0) || ((bool) pRow["HIERARCHY_IS_VISIBLE"]);
            this.mDimensionType = (eDimensionType) ((short) pRow["DIMENSION_TYPE"]);
            this.mStructure = (eHierarchyStructure) ((short) pRow["STRUCTURE"]);
            this.mHierarchyOrigin = (pRow.Table.Columns.IndexOf("HIERARCHY_ORIGIN") < 0) ? eHierarchyOrigin.UserDefined : ((eHierarchyOrigin) ((ushort) pRow["HIERARCHY_ORIGIN"]));
            this.mInstanceSelection = ((pRow.Table.Columns.IndexOf("INSTANCE_SELECTION") < 0) || (pRow["INSTANCE_SELECTION"] is DBNull)) ? eInstanceSelection.None : ((eInstanceSelection) ((ushort) pRow["INSTANCE_SELECTION"]));
            this.mGroupingBehaviour = (pRow.Table.Columns.IndexOf("GROUPING_BEHAVIOR") < 0) ? 0 : ((ushort) pRow["GROUPING_BEHAVIOR"]);
            this.mLevelList = new MdObjectList<MdLevel>();
        }

        public MdHierarchy(string pCubeName, string pDimensionUniqueName, string pUniqueName, string pName, string pCaption, string pDescription, string pAllMember, string pDefaultMember, string pDisplayFolder, int pOrdinal, int pCardinality, bool pIsWriteEnabled, bool pIsVisible, eDimensionType pType, eHierarchyStructure pStructure, eHierarchyOrigin pOrigin, eInstanceSelection pInstanceSelection, int pGroupingBehaviour)
        {
            this.mCubeName = pCubeName;
            this.mDimensionUniqueName = pDimensionUniqueName;
            this.mHierarchyUniqueName = pUniqueName;
            this.mHierarchyName = pName;
            this.mHierarchyCaption = pCaption;
            this.mDescription = pDescription;
            this.mAllMember = pAllMember;
            this.mDefaultMember = pDefaultMember;
            this.mDisplayFolder = pDisplayFolder;
            this.mHierarchyOrdinal = pOrdinal;
            this.mHierarchyCardinality = pCardinality;
            this.mIsWriteEnabled = pIsWriteEnabled;
            this.mIsVisible = pIsVisible;
            this.mDimensionType = pType;
            this.mStructure = pStructure;
            this.mHierarchyOrigin = pOrigin;
            this.mInstanceSelection = pInstanceSelection;
            this.mGroupingBehaviour = pGroupingBehaviour;
            this.mLevelList = new MdObjectList<MdLevel>();
        }

        public void SetCaption(string pCaption)
        {
            this.mHierarchyCaption = pCaption;
        }

        public void SetUniqueCaption(string pString)
        {
            this.mUniqueCaption = pString;
        }

        public override string ToString()
        {
            return this.mUniqueCaption;
        }

        public string AllMember
        {
            get
            {
                return this.mAllMember;
            }
        }

        public string Caption
        {
            get
            {
                return this.mHierarchyCaption;
            }
        }

        public int Cardinality
        {
            get
            {
                return this.mHierarchyCardinality;
            }
        }

        public string CubeName
        {
            get
            {
                return this.mCubeName;
            }
        }

        public string DefaultMember
        {
            get
            {
                return this.mDefaultMember;
            }
        }

        public string Description
        {
            get
            {
                return this.mDescription;
            }
        }

        public string DimensionUniqueName
        {
            get
            {
                return this.mDimensionUniqueName;
            }
        }

        public string DisplayFolder
        {
            get
            {
                return this.mDisplayFolder;
            }
        }

        public int GroupingBehaviour
        {
            get
            {
                return this.mGroupingBehaviour;
            }
        }

        public eInstanceSelection InstanceSelection
        {
            get
            {
                return this.mInstanceSelection;
            }
        }

        public bool IsVisible
        {
            get
            {
                return this.mIsVisible;
            }
        }

        public bool IsWriteEnabled
        {
            get
            {
                return this.mIsWriteEnabled;
            }
        }

        public MdObjectList<MdLevel> Levels
        {
            get
            {
                return this.mLevelList;
            }
        }

        public string Name
        {
            get
            {
                return this.mHierarchyName;
            }
        }

        public int Ordinal
        {
            get
            {
                return this.mHierarchyOrdinal;
            }
        }

        public eHierarchyOrigin Origin
        {
            get
            {
                return this.mHierarchyOrigin;
            }
        }

        public eHierarchyStructure Structure
        {
            get
            {
                return this.mStructure;
            }
        }

        public eDimensionType Type
        {
            get
            {
                return this.mDimensionType;
            }
        }

        public string UniqueCaption
        {
            get
            {
                return this.mUniqueCaption;
            }
        }

        public string UniqueName
        {
            get
            {
                return this.mHierarchyUniqueName;
            }
        }
    }
}

